
const app = getApp()
var f = require('../../utils/files.js');

/*

        //1，加载开通城市
        //2，加载域名列表
        //3，加载商品类别
*/

Page({

  data: {
    openCity: [],     //开通城市数组
    province_index: 0,   //省下标
    city_index: 0,   //市下标
    county_index: 0,   //县下标
  },

  onShow() {

  },

  onLoad() {
    var t = this

    t.setData({
      openCity: app.globalData.openCity.openCity
    })

  },





  //确定选择城市
  formSubmit(e) {
    var data = this.data;
    var currentCity = data.openCity[data.province_index].city[data.city_index].county[data.county_index];
    app.globalData.currentCity = currentCity;

    //当前选择城市保存到文件
    app.F(app.globalData.currentCityPath, JSON.stringify(currentCity), function (res) {
      wx.switchTab({
        url: '../index/index',
      })
    });

  },




  //城市切换 
  bindPickerChange(e) {
    var t = this;
    var index = parseInt(e.detail.value);
    var type = e.target.dataset.type;
    switch (type) {
      case 'province':
        t.setData({
          province_index: index,
          city_index: 0,
          county_index: 0
        })
        break;

      case 'city':
        t.setData({
          city_index: index,
          county_index: 0
        })
        break;

      case 'county':
        t.setData({
          county_index: index,
        })
        break;
    }
  },




})